<?php
require_once 'ApplianceView.php';
	class ApplianceManager{
	
			public function validate($snum,$type,$term,$controlNo,$dateInstalled,$dateCancelled,$remarks){
		
				if(is_numeric($snum)&&($type!=null||$type!="")&&($term!=null||$term!="")&&($controlNo!=null||$controlNo!="")&&($dateInstalled!=null||$dateInstalled!="")){
					return true;
				}else{
					return false;
				}
		}
		
		public function insertAppliance($snum,$type,$term,$controlNo,$dateInstalled,$dateCancelled,$remarks){	
			$conn=oci_connect("naiad","1234","localhost/XE");
			if(!$conn){
				$err[] = "Connection error!". var_dump(oci_error());
				echo '<script> alert("'.$err.'") </script>';
				die();
				oci_close($conn);
			}
			else{
				$stapp = oci_parse($conn,"insert into appliance(controlno,studentno,type,term,dateinstalled,datecancelled,remarks) values(:controlno,:studentno,:type,:term,:dateinstalled,:datecancelled,:remarks)");
				oci_bind_by_name($stapp, ":studentno", $snum);
				oci_bind_by_name($stapp, ":type", $type);
				oci_bind_by_name($stapp, ":term", $term);
				oci_bind_by_name($stapp, ":controlno", $controlNo);
				oci_bind_by_name($stapp, ":dateinstalled", $dateInstalled);
				oci_bind_by_name($stapp, ":datecancelled", $dateCancelled);
				oci_bind_by_name($stapp, ":remarks", $remarks);
				$exec1 = oci_execute($stapp);
				if($exec1==true){
					return 1;
				}
				oci_commit($conn);
				//oci_free_statement($stid);
				oci_close($conn);
			}	
		}		
	}//class
?>
